<script>
import { NavBar, Tab, Tabs, Empty, List, Toast } from "vant";
import axios from "@/utils/request";
export default {
  components: {
    [NavBar.name]: NavBar,
    [Tab.name]: Tab,
    [Tabs.name]: Tabs,
    [Empty.name]: Empty,
    [List.name]: List,
  },
  methods: {
    goBack() {
      // 返回点击进来前的页面
      this.$router.back();
    },
    guanzhuAction() {
      this.follow = true;
      Toast({
        message: "关注成功",
        icon: "success",
      });
    },
    quxiaoAction() {
      this.follow = false;
      Toast({
        message: "取消关注",
        icon: "success",
      });
    },
    //  获取菜谱数据
    menu() {
      axios
        .get("/")
        .then((res) => {
          if (res.data.data.length != 0) {
            this.list1.push(res.data.data);
            this.loading1 = false;
          } else {
            this.finished1 = true;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 获取作品数据
    works() {
      axios
        .get("/")
        .then((res) => {
          if (res.data.data.length != 0) {
            this.list2.push(res.data.data);
            this.loading2 = false;
          } else {
            this.finished2 = true;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
  data() {
    return {
      // 所在列表
      active: 0,

      // 菜谱数据及状态
      list1: [],
      loading1: false,
      loading2: false,

      // 作品数据及状态
      list2: [],
      finished1: false,
      finished2: false,

      follow: false,
    };
  },
};
</script>
<template>
  <div>
    <div class="page">
      <!-- 头部 -->
      <header>
        <i class="iconfont icon-arrow-left" @click="goBack"></i>
        <h3>用户中心</h3>
      </header>
      <div class="con_wrap">
        <div class="personalInformation">
          <div class="userinformation">
            <div class="headPortrait">
              <img
                src="https://img1.baidu.com/it/u=1960110688,1786190632&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=281"
                alt=""
              />
            </div>
            <div class="information">
              <div class="left">
                <h2>西瓜</h2>
                <button
                  @click="guanzhuAction"
                  v-if="follow === false"
                  class="btn1"
                >
                  <i class="iconfont icon-jiajianzujianjiahao"></i>关注
                </button>
                <button
                  @click="quxiaoAction"
                  v-if="follow === true"
                  class="btn2"
                >
                  已关注
                </button>
              </div>
              <p><span>女</span><span>2021年加入</span></p>
            </div>
          </div>
          <div class="otherInformation">
            <router-link :to="{ name: 'fabulous' }">
              <h2>10</h2>
              <p>关注</p>
            </router-link>
            <span></span>
            <router-link :to="{ name: 'fabulous' }">
              <h2>200</h2>
              <p>粉丝</p>
            </router-link>
            <span></span>
            <router-link :to="{ name: 'follow' }">
              <h2>10</h2>
              <p>收到的点赞</p>
            </router-link>
          </div>
        </div>

        <van-tabs
          v-model="active"
          swipeable
          background="transparent"
          class="tabs"
        >
          <van-tab :title="'菜谱 ' + 4">
            <van-list
              v-model="loading1"
              :finished="finished1"
              finished-text="没有更多了"
              @load="menu"
            >
              <van-empty
                class="custom-image"
                image="https://img01.yzcdn.cn/vant/custom-empty-image.png"
                description="无菜谱"
                v-if="list1.length == 0"
              />

              <div class="menu_wrap" v-else>
                <router-link
                  :to="{ name: 'detail', query: { x: 1 } }"
                  class="menu_box"
                  v-for="item in list1"
                  :key="item.title"
                >
                  <img v-lazy="item.img" alt="" />
                  <p class="van-ellipsis">{{ item.title }}</p>
                </router-link>
              </div>
            </van-list>
          </van-tab>

          <van-tab :title="'作品 ' + 3">
            <van-list
              v-model="loading2"
              :finished="finished2"
              finished-text="没有更多了"
              @load="works"
            >
              <van-empty
                class="custom-image"
                image="https://img01.yzcdn.cn/vant/custom-empty-image.png"
                description="无作品"
                v-if="list2.length == 0"
              />
              <div class="works_wrap" v-else>
                <router-link
                  :to="{ name: 'detail', query: { x: 1 } }"
                  class="works_box"
                  v-for="item in list2"
                  :key="item.title"
                >
                  <img v-lazy="item.img" alt="" />
                </router-link>
              </div>
            </van-list>
          </van-tab>
        </van-tabs>
      </div>
    </div>
    <transition name="van-slide-right">
      <router-view></router-view>
    </transition>
  </div>
</template>

<style lang="scss" scoped>
.page {
  overflow: hidden;
  header {
    height: 50px;
    line-height: 50px;
    i {
      font-size: 18px;
      position: absolute;
      left: 20px;
    }
    h3 {
      text-align: center;
      font-weight: 700;
    }
  }
}
.con_wrap {
  height: calc(100% - 50px);
  width: 100%;
  background: #fff;
  padding-top: 8vw;
  overflow-y: auto;
  overflow-x: hidden;
  .personalInformation {
    box-shadow: 0 0 10.6667vw 5.3333vw #f0f1f4;
    margin: 0 5vw;
    margin-top: 5.3333vw;
    margin-bottom: 4vw;
    padding: 0 4vw;
    background: #ffffff;
    border-radius: 2.6667vw;
    .userinformation {
      padding: 5.3333vw 0;
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: relative;

      .headPortrait {
        transform: translateY(-20%);
        border-radius: 100%;
        width: 24vw;
        height: 24vw;
        padding: 1.3333vw;
        background: #fff;
        box-shadow: 0 0 4vw 0.5333vw #ccc;
        position: absolute;

        img {
          border-radius: 100%;
          width: 100%;
          height: 100%;
        }
      }
      .information {
        flex: 1;
        margin-left: 32vw;
        .left {
          display: flex;
          justify-content: space-between;
          .btn1 {
            width: 70px;
            height: 25px;
            font-size: 12px;
            border: none;
            border-radius: 15px;
            background-color: rgba(102, 110, 232, 1);
            color: #fff;
            i {
              font-size: 12px;
              padding: 0 5px 0 0;
            }
          }
          .btn2 {
            width: 70px;
            height: 25px;
            font-size: 12px;
            border: none;
            border-radius: 15px;
            color: #c4bfbf;
            background-color: #cccccc49;
          }
        }
        h2 {
          font-size: 4.8vw;
          font-weight: 800;
          margin-bottom: 5.3333vw;
          display: flex;
          justify-content: space-between;
          align-items: center;
          a {
            font-weight: 500;
            color: #000;
            i {
              font-size: 6.6667vw;
            }
          }
        }
        p {
          font-size: 3.2vw;
          color: #8d92a3;
          span:first-of-type {
            margin-right: 1.3333vw;
          }
        }
      }
    }
    .otherInformation {
      padding: 5.3333vw 0;
      display: flex;
      justify-content: space-around;
      align-items: center;
      span {
        width: 0.2667vw;
        height: 4vw;
        background: #ccc;
      }
      a {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        h2 {
          margin-bottom: 2vw;
          color: #000;
          font-size: 4.2667vw;
        }
        p {
          font-size: 2.6667vw;
          color: #8d92a3;
        }
      }
    }
  }
  .tabs {
    padding-bottom: 10vw;
    .menu_wrap {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      margin: 0 5vw;
      margin-top: 5.3333vw;

      .menu_box {
        flex-shrink: 0;
        width: 43vw;
        height: 65vw;
        img {
          width: 100%;
          height: 85%;
          border-radius: 2.6667vw;
        }
        p {
          margin-top: 2.6667vw;
          font-size: 4.2667vw;
          color: #000;
        }
      }
    }
    .works_wrap {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      margin: 0 1vw;
      margin-top: 5.3333vw;
      .works_box {
        margin-top: 2.6667vw;
        flex-shrink: 0;
        width: 32vw;
        height: 35vw;
        img {
          width: 100%;
          height: 100%;
          border-radius: 1.3333vw;
        }
      }
    }
  }
}
</style>
